<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <%@ include file="/WEB-INF/views/modules/commons/head.jsp" %>
    <!-- 组件的css -->
    <link rel="stylesheet" href="<s:url value="/assets/web/common/lulu_zujian/ui.css"></s:url>">
    <!-- 消息列表 CSS -->
    <link rel="stylesheet" href="<s:url value="/assets/web/css/user/userlist.css"></s:url>">
    <style>
        /* 公用边距 */
        #content-main {
            padding: 50px 0px 0;
            position: relative;
        }

        .export-excel {
            position: absolute;
            top: 10px;
            right: 6%;
        }

        .export-excel > input {
            height: 35px;
        }
    </style>
    <title>县领导预发短信</title>
</head>

<body class="bgcolor">
<%@ include file="/WEB-INF/views/modules/commons/nav.jsp" %>
<%@ include file="/WEB-INF/views/modules/commons/menu.jsp" %>
<table></table>
<div class="av row J_mainContent" id="content-main">
    <div class="user-manger" style="display: block;">
        <div class="container">
            <table class="project-info">
                <thead>
                <tr>
                    <th>日期</th>
                    <th>项目名</th>
                    <th>类别</th>
                    <th>责任单位</th>
                    <th>收件人</th>
                    <th>电话号码</th>
                    <th>短信内容</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="main">
                </tbody>
            </table>
        </div>

        <div class="footer">
            <ul class="pagination" id="pagination0"></ul>
        </div>
    </div>
</div>
<%@ include file="/WEB-INF/views/modules/commons/foot.jsp" %>
<script src="<s:url value="/assets/web/common/date/laydate.dev.js"></s:url>"></script>
<script>
    <%--分页请求--%>
    var pages = $('#pagination0').jqPaginator({
        totalPages: ${totalPage},
        visiblePages: 5,
        currentPage: 1,
        first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
        onPageChange: function (num) {
            $('#text').html('当前第' + num + '页');
            $.ajax({
                type: "POST",
                url: "/temporaryMessage/list",
                dataType: "json",
                data: ({"page": num - 1}),
                success: function (model) {
                    var html = "";
                    for (var i = 0; i < model.model.length; i++) {
                        var list = model.model[i];
                        var type = "";
                        var name = "";
                        var name2 = "";
                        if (list.type == 0) {
                            type = "未发送";
                            name = "发送";
                            name2 = "";
                        } else if (list.type == 1) {
                            type = "已发送";
                        } else if (list.type == 2) {
                            type = "取消发送";
                        }
                        // html += "<tr class =\"" + i + "\">"+
                        //     "+<td>" + list.createDate + "</td>" +
                        //     "+<td>" + list.projectName + "</td>" +
                        //     "+<td>" + type + "</td>" +
                        //     "+<td>" + list.resDept + "</td>" +
                        //     "+<td>" + list.recipients + "</td>" +
                        //     "+<td>" + list.phone + "</td>" +
                        //     "+<td>" + list.text + + "</td>" +
                        //     "+<td><button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\" onclick='ss("'+list.sysId+'")'>" +
                        //     "发送" +
                        //     "</button>&nbsp&nbsp&nbsp<button type=\"button\" class=\"btn btn-success\" data-dismiss=\"modal\" onclick='ss(+list.sysId+',2'+)'>" +
                        //     "取消发送" +
                        //     "</button></td>";
                        html += '\
                    <tr class="' + i + '">\
                        <td style="width: 95px;">' + list.createDate + '</td>\
                        <td>' + list.projectName + '</td>\
                        <td style="width: 75px;">' + type + '</td>\
                        <td>' + list.resDept +'</td>\
                        <td style="width: 95px;">' + list.recipients + '</td>\
                        <td style="width: 105px;">' + list.phone + '</td>\
                        <td>' + list.text + '</td>\
                        <td><button style="width: 80px;" type="button" class="btn-danger" data-dismiss="modal" onclick="editTemporaryMessage(' + 1 + ',\'' + list.sysId + '\');">发送短信</button></td>\
                        <td><button style="width: 115px;" type="button" class="btn-success" data-dismiss="modal" onclick="editTemporaryMessage(' + 2 + ',\'' + list.sysId + '\')">取消发送短信</button></td>' +
                            '</t>';
                    }
                    $("#main").html(html);
                    $("#page").html(num);
                },
                error: function (model) {

                }
            })
        }

    });

    function editTemporaryMessage(type, sysId) {
        var postdata = {
            "sysId": sysId,
            "type": type
        };
        $.ajax({
            type: "post",
            url: "/temporaryMessage/editTemporaryMessage",
            dataType: "json",
            data: JSON.stringify(postdata),
            contentType: 'application/json;charset=utf-8',
            success: function (res) {
                if (res.code == '200') {
                    alert("发送短信成功！");
                    location.reload();
                } else if (res.code == '300') {
                    alert("取消发送短信成功");
                } else if (res.code == '500') {
                    alert("操作失败，" + res.msg);
                }

            },
            error: function (res) {

            }
        });
    }
</script>
</body>

</html>